import logging

import config


class RegisterLoginApi:
    # 1.获取图片验证码接口
    @classmethod
    def get_image_code(cls,session,r):
        url = config.Host+f"/common/public/verifycode1/{r}"
        logging.info(f"获取图片得接口得请求体={url}")
        resp = session.get(url)
        return resp
    # 2.获取短信验证码接口
    @classmethod
    def get_phone_code(cls,session,phone,imgVerifyCode):
        url = config.Host+"/member/public/sendSms"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"phone":phone,"imgVerifyCode":imgVerifyCode,"type":"reg"}
        logging.info(f"获取短信验证码接口得请求体url={url}")
        logging.info(f"获取短信验证码接口得请求体body={body}")
        resp = session.post(url=url,headers=header,data=body)
        return resp
    # 3.注册接口
    @classmethod
    def register(cls,session,phone,password,verifycode,phone_code):
        url = config.Host+"/member/public/reg"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"phone":phone,"password":password,"verifycode":verifycode,"phone_code":phone_code,"dy_server":"on","invite_phone":""}
        logging.info(f"注册接口得请求体body={body}")
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 4.登录接口
    @classmethod
    def login(cls,session,keywords,password):
        url = config.Host + "/member/public/login"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {"keywords": keywords, "password": password}
        logging.info(f"登录接口得请求体body={body}")
        resp = session.post(url=url, headers=header, data=body)
        return resp
    # 5.查询登录状态接口
    @classmethod
    def query_login_status(cls,session):
        url = config.Host + "/member/public/islogin"
        logging.info(f"查询登录得接口得请求体={url}")
        resp = session.post(url=url)
        return resp